<?php

/**
 * O2O团购PC版本
 * ============================================================================
 * * 版权所有 2009-2016 郑州司科计算机科技有限公司，并保留所有权利。
 * 购买网址: http://www.jzphp.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
  * 咨询电话：400-823-0371 QQ：313999875
 * ============================================================================
 * $Author: zzsike $
 * $Time 2016-02-03 sammy $
*/


/* *
 * 用户提现

 *************************注意*************************
 * 
 */
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/app.php');

need_manager();

$action = strval($_GET['action']);
$id = abs(intval($_GET['id']));

if ( 'withdrawview' == $action ) {
	$withdraw = Table::Fetch('withdraw', $id);
	$admin = Table::Fetch('user', $withdraw['admin_id']);
	$withdraw_state = array(
		'1' => '待提现',
		'2' => '拒绝',
		'4' => '正在提现',
		'8' => '已提现',
	);
	$html = render('manage_withdraw_ajax_dialog_detail');
	json($html, 'dialog');
}
elseif ( 'withdrawdel' == $action ) {
	$withdraw = Table::Fetch('withdraw', $id);
	if ( !$withdraw ) json('记录不存在', 'alert');
	Table::Delete('withdraw', $withdraw['id']);
	Session::Set('notice', "删除提现记录 {$withdraw['id']} 成功");
	json(null, 'refresh');
}
elseif ( 'withdrawaudit' == $action ) {
	$withdraw = Table::Fetch('withdraw', $id);
	
	$withdraw_state = array(
		'1' => '待提现',
		'2' => '拒绝',
		'4' => '正在提现',
		'8' => '已提现',
	);
	$html = render('manage_withdraw_ajax_dialog_audit');
	json($html, 'dialog');
}
elseif ( 'withdrawsubmitAudit' == $action ) {
	$withdraw = Table::Fetch('withdraw', $id);
	$state = abs(intval($_GET['state']));
	$remark = $_GET['remark'];
	$admin_id=$login_user_id;
	Table::UpdateCache('withdraw', $id, array(
					'state' => $state,
					'remark' => $remark,
					'admin_id' => $admin_id,
	));
	if($state==8){
		$user=Table::Fetch('user',$withdraw['user_id']);
		$balance=$user['money']-$withdraw['money'];
		Table::UpdateCache('user',$user['id'],array(
							'money'=>$balance,
		));
		$f = array(
				'user_id' => $withdraw['user_id'],
				'admin_id' => $admin_id,
				'direction' => 'expense',
				'money' => $withdraw['money'],
				'action' => 'withdraw',
				'create_time' => time(),
				);
		
		$q = DB::Insert('flow', $f);
	}
		json( array(
					array('data'=>'修改成功', 'type' => 'alert',),
					array('data'=>'X.boxClose();', 'type' => 'eval',),
					array('data'=>'null', 'type' => 'refresh',),
				   ), 'mix');
}
